﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;
using System.Collections;

namespace WXYW
{
    public partial class ProblemReportProblemDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ProblemReportService reportService = new ProblemReportService();
                ProblemReport reportEntity = reportService.GetProblemReport(Request.QueryString["Code"]);
                reportTypeLbl.Text = reportEntity.ReportType;
                productLineTypeLabel.Text = reportEntity.ProductLineType;
                problemTypeLabel.Text = reportEntity.ProblemType;
                productVersionLabel.Text = reportEntity.ProductVersion;
                if (!reportEntity.UserReference.IsLoaded)
                {
                    reportEntity.UserReference.Load();
                }
                createByLabel.Text = reportEntity.User.ContactPerson;
                createDateLabel.Text = reportEntity.CreateDate.ToString("yyyy-MM-dd");
                productModelLabel.Text = reportEntity.ProductType;
                solutionTxtBox.Text = reportEntity.Solution;
                descriptionTxtBox.Text = reportEntity.ProblemDescription;
                problemReasonLabel.Text = reportEntity.ProblemReason;
                subjectTextBox.Text = reportEntity.Subject;
                if (reportEntity.SecurityType.Equals("ASC"))
                {
                    SecurityRadioButtonList.SelectedIndex = 1;
                }
            }
        }

        protected void problemFileLnkBtn_Click(object sender, EventArgs e)
        {
            ReportFileModalPopupExtender.Show();
        }

        protected void backLinkButton_Click(object sender, EventArgs e)
        {
            Response.Redirect(string.Format("ProblemReportSearch.aspx?T={0}&P={1}", Request.QueryString["T"], Request.QueryString["P"]));
        }

        protected void ReportFileGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
                ((HyperLink)e.Row.FindControl("ViewFileHyperLink")).NavigateUrl = string.Format("~/ReportFile/{0}_{1}", ((ProblemReportFile)e.Row.DataItem).ID, ((ProblemReportFile)e.Row.DataItem).FileName);
            }
        }

        protected void ModalPopupExtender1_Load(object sender, EventArgs e)
        {
            ProblemReportService reportService = new ProblemReportService();
            IQueryable<ProblemReportFile> files = reportService.GetReportFiles(Request.QueryString["Code"]);
            ReportFileGridView.DataSource = files;
            ReportFileGridView.DataBind();
        }
    }
}
